﻿using KELT.KELTObjects.ViewportObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace KELT.Animation.Animation2D
{

    public class ColorAni : IAnimation
    {
        private ColorAnimation colorAni;


        public ColorAni()
        {
            colorAni = new ColorAnimation();

        }

        public override void SetAnimation(Storyboard myStoryboard, ViewportObj obj)
        {
            animationName = "색상애니메이션";

            
            double animationTime = endTime - startTime;
            colorAni.Duration = TimeSpan.FromSeconds(animationTime);
            colorAni.BeginTime = TimeSpan.FromSeconds(startTime);

            Random rand = new Random();
            byte[] colorBytes = new byte[3];
            rand.NextBytes(colorBytes);

            Color randomColor = Color.FromRgb(colorBytes[0], colorBytes[1], colorBytes[2]);


            colorAni.To = randomColor;// Colors.Green;


            Storyboard.SetTargetName(colorAni, AnimationInfo.ANIMATION_ALPHA + obj.getIndexNumber());
            Storyboard.SetTargetProperty(colorAni, new PropertyPath(SolidColorBrush.ColorProperty));
            myStoryboard.Children.Add(colorAni);

        }

        public override void changeAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(colorAni);

            colorAni.Duration = TimeSpan.FromSeconds(endTime - startTime);
            colorAni.BeginTime = TimeSpan.FromSeconds(startTime);
            myStoryboard.Children.Add(colorAni);

        }

        public override void deleteAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(colorAni);
        }

        public void setColor(Color newColor)
        {
            colorAni.To = newColor;
        }


    }
}
